<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<style type="text/css">
div{margin:0px;padding:0px;}
#main{width:380px;height:102px;overflow-y:auto;border:1px solid #ddd;padding:0 10px 0 10px;}
#content{width:350px;line-height:20px;}
</style>
<script type="text/javascript">
  window.onload=function(){
    var i=1;
    
    var btn=document.getElementById('btnSend');//添加消息的按钮
    
    var mai=document.getElementById('main');
    btn.onclick=function(){
        mai.innerHTML+='消息内容'+i+'<br/>';
       //hid.scrollIntoView(false);//方式1通过调用隐藏元素的scrollIntoView()方法使其可见
        mai.scrollTop=mai.scrollHeight;//方式2通过设置滚动高度
        i++;
    }
    
    
    var area=document.getElementById('area');
	   var btn = document.getElementById('send');
	   btn.onclick=function(){
		   
	        area.innerHTML+='消息内容<br/>';
	      
	        area.scrollTop=area.scrollHeight;
	        
	    }
  }
</script>
<body>
<div id="main">
 
</div>
<input type="button" id="btnSend" value="添加"/>
</body>
</html>